/***************************************************************************
 *   Copyright (C) 2009 by Zheng Yonglei
 *   zhengyonglei@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef TestWidget_H
#define TestWidget_H

#include <QtGui/QWidget>


#include "ui_TestWidget.h"

#include "Dictionary.h"
#include "TestEndDialog.h"
#include "TestManager.h"
#include "TestPlanner.h"

#define ANS_YES "ans_yes" //answer yes
#define ANS_NO "ans_no" //answer no
#define CFM_YES "cfm_yes" //confirm yes
#define CFM_NO "cfm_no" //confirm no
#define TEST_NEXT "test_next" //test next word

enum TestProgress
{
	TP_None,
	TP_Begin,
	TP_Confirm,
	TP_Finish
};

class TestWidget : public QWidget
{
    Q_OBJECT

public:
    TestWidget(QWidget *parent = 0);
    ~TestWidget();

    TestManager& testManager(){return mTestManager;}

    bool prepareToTest();
    void setDisplayFont(QFont& font);

private:
    void testNextWord();
    bool endCurTest();

    void showDictionary(bool showDict);
    void quickLookupDictionary(QString key);

    void begin();
    void confirm();
    void testPassed();
    void testFailed(QString reason = QString());

public slots:
    void anchorClicked(const QUrl&);
    void timeout();

signals:
	void updateMainBulletin();
	void curTestFinished();
	void showSelectListDialog();
	void showAnalysisDialog();

private:
    Ui::TestWidgetClass ui;

    Dictionary* mDictionary;
    float mDictAreaWidthRate;

    EditDistance mEditDistance;

    TestManager mTestManager;
    TestPlanner mTestPlanner;
    TestProgress mTestProgress;

    QTimer mTimer;
    long mMsElapsed;
    int mTestBeginWaitMaxMs;
    int mTestConfirmWaitMinMs;
};

#endif // TestWidget_H
